package ch.sv7.tool.dbmanager.db;

import java.util.StringTokenizer;

import ch.sv7.tool.dbmanager.DbManagerException;

public class Manager {

	public static void copy(TableReader reader, TableWriter writer, DatabaseSchema schema, String tableNames[])
			throws DbManagerException {
		for (int i = 0; i < tableNames.length; i++) {
			String tableName = tableNames[i];
			TableSchema tableSchema = schema.getTableSchema(tableName);
			if (tableSchema == null)
				throw new DbManagerException("Unable to find table : " + tableName + " in structure");
			System.out.println("Copying table : " + tableSchema.getFullName());
			reader.transferTable(tableSchema, writer);
		}

	}

	public static void copy(TableReader reader, TableWriter writer, DatabaseSchema schema, String tables)
			throws DbManagerException {
		StringTokenizer tokens = new StringTokenizer(tables, ",");
		String result[] = new String[tokens.countTokens()];
		int i = 0;
		while (tokens.hasMoreTokens()) {
			String table = tokens.nextToken().trim();
			result[i++] = table;
		}
		copy(reader, writer, schema, result);
	}
}
